#pragma once

#include <iostream>
#include <string>
#include <vector>
#include <ctemplate/template.h>

// #include "Model_File.hpp"
#include "Model_MySQL.hpp"

using namespace Model_NS;

namespace View_NS
{
    const std::string html_path = "./Template_html/";

    class View
    {
    public:
        View(){};
        ~View(){};
    public:
        // 将所有题目的相关信息渲染成网页
        void AllExpandHtml(const std::vector<Question>& qeustions , std::string* html)
        {
            // 1、形成路径
            std::string src_html =  html_path + "AllQuestions.html";
            // 2、形成数据字典
            ctemplate::TemplateDictionary dict("all_questions");
            for(const auto & q : qeustions)
            {
                ctemplate::TemplateDictionary* sub_dict = dict.AddSectionDictionary("question_list");
                sub_dict->SetValue("number",q._number);
                sub_dict->SetValue("title",q._title);
                sub_dict->SetValue("difficulty",q._difficulty);
            }
            // 3、获取被被渲染html
            ctemplate::Template* tpl = ctemplate::Template::GetTemplate(src_html,ctemplate::DO_NOT_STRIP);

            // 4、开始渲染
            tpl->Expand(html,&dict);
        }
        
        // 将一个题目的相关信息渲染成网页
        void OneExpandHtml(const Question& q,std::string* html)
        {
            // 1、形成路径
            std::string src_html = html_path + "OneQuestion.html";
            // 2、形成数据字典
            ctemplate::TemplateDictionary dict("one_question");
            dict.SetValue("number",q._number);
            dict.SetValue("title",q._title);
            dict.SetValue("difficulty",q._difficulty);
            dict.SetValue("desc",q._desc);
            dict.SetValue("default_code",q._default);
            // 3、获取被被渲染html
            ctemplate::Template* tpl = ctemplate::Template::GetTemplate(src_html,ctemplate::DO_NOT_STRIP);
            // 4、开始渲染
            tpl->Expand(html,&dict);
        }
    };
}